package com.qc.bus.controller;


import com.baomidou.mybatisplus.extension.api.ApiController;
import com.qc.bus.entity.BusInport;
import com.qc.bus.service.BusInportService;
import com.qc.bus.vo.InportVo;
import com.qc.sys.common.ActiveUser;
import com.qc.sys.common.Constant;
import com.qc.sys.common.ResultObj;
import com.qc.sys.entity.SysUser;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

/**
 * (BusInport)表控制层
 *
 * @author AltmanQccc
 * @since 2020-09-09 19:33:57
 */
@RestController
@RequestMapping("inport")
public class BusInportController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private BusInportService busInportService;

    /**
     * 查询并展示数据
     * */
    @GetMapping("loadAllInport")
    public Object loadAllInport(InportVo inportVo){
        return this.busInportService.queryAllInport(inportVo);
    }

    /**
     * 添加进货
     * */
    @PostMapping("addInport")
    public ResultObj addInport(BusInport inport){
        try {
            ActiveUser activeUser = (ActiveUser) SecurityUtils.getSubject().getPrincipal();
            SysUser user = activeUser.getUser();
            inport.setInporttime(new Date());
            inport.setOperateperson(user.getName());
            this.busInportService.InsertInport(inport);
            return ResultObj.ADD_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.ADD_ERROR;
        }
    }

    /**
     * 修改进货
     * */
    @PostMapping("updateInport")
    public ResultObj updateInport(BusInport inport){
        try {
            this.busInportService.UpdateInport(inport);
            return ResultObj.UPDATE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.UPDATE_ERROR;
        }
    }

    /**
     * 删除进货
     * */
    @PostMapping("deleteInport")
    public ResultObj deleteInport(Integer id){
        try {
            this.busInportService.removeById(id);
            return ResultObj.DELETE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.DELETE_ERROR;
        }
    }

}